package com.fowo.api.syncAmazon.service.impl;

import com.fowo.api.syncAmazon.api.BusinessReportsService;
import com.fowo.api.syncAmazon.mapper.AmazonTmpMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 业务报表
 */
@Service
@Slf4j
public class BusinessReportsServiceImpl {
    @Resource
    private BusinessReportsService businessReportsService;
    @Resource
    private AmazonTmpMapper amazonTmpMapper;

    public void syncBusinessReportsBySku() throws Exception {
        log.info("清空SKU业务报表临时表");
        amazonTmpMapper.deleteTmpBusinessReportsBySku();

        log.info("拉去SKU业务报表数据到临时表");
        businessReportsService.getBusinessReportsBySku();

        log.info("更新SKU业务报表到业务表");
        amazonTmpMapper.updateTmpBusinessReportsBySku();
        amazonTmpMapper.insertTmpBusinessReportsBySku();

    }

    public void syncBusinessReportsByChild() throws Exception {
        log.info("清空子产品业务报表临时表");
        amazonTmpMapper.deleteTmpBusinessReportsByChild();
        log.info("拉去子产品业务报表数据到临时表");
        businessReportsService.getBusinessReportsByChild();

        log.info("更新子产品业务报表到业务表");
        amazonTmpMapper.updateTmpBusinessReportsByChild();
        amazonTmpMapper.insertTmpBusinessReportsByChild();
    }

    public void syncBusinessReportsByParent() throws Exception {
        log.info("清空父产品业务报表临时表");
        amazonTmpMapper.deleteTmpBusinessReportsByParent();

        log.info("拉去父产品业务报表数据到临时表");
        businessReportsService.getBusinessReportsByParent();

        log.info("更新父产品业务报表到业务表");
        amazonTmpMapper.updateTmpBusinessReportsByParent();
        amazonTmpMapper.insertTmpBusinessReportsByParent();
    }
}
